package com.yilin.tms.truck.service.impl;


import com.google.gson.reflect.TypeToken;
import com.yilin.commons.util.JsonUtil;
import com.yilin.tms.core.entity.truck.TransportLicense;
import com.yilin.tms.core.entity.truck.TravelLicense;
import com.yilin.tms.core.entity.truck.TruckVehicle;

import com.yilin.tms.truck.mapper.TravelLicenseMapper;
import com.yilin.tms.truck.service.IMigrationService;
import com.yilin.tms.truck.service.ITruckVehicleService;
import com.yilin.tms.truck.mapper.TransportLicenseMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class MigrationService implements IMigrationService {

    @Resource
    private ITruckVehicleService vehicleService;
    @Resource
    private TravelLicenseMapper travelLicenseMapper;
    @Resource
    private TransportLicenseMapper transportLicenseMapper;

    //TODO:批量写入车辆
    @Override
    public void insertTruckVehicleList(List<Map<String, Object>> mapList){
        List<TruckVehicle> list = JsonUtil.jsonToObject(JsonUtil.objectToJson(mapList),new TypeToken< List<TruckVehicle>>(){});
        vehicleService.saveOrUpdateBatch(list,99999);
    }

    //TODO:批量写入认证
    @Override
    public <T>  void insertAuthList(List<Map<String, Object>> mapList, Class<T> cls){
        for (Map<String, Object> auth : mapList) {
            if (cls.equals(TravelLicense.class)) travelLicenseMapper.insert(JsonUtil.mapToObject(auth,new TypeToken<TravelLicense>(){}));
            if (cls.equals(TransportLicense.class)) transportLicenseMapper.insert(JsonUtil.mapToObject(auth,new TypeToken<TransportLicense>(){}));
        }
    }

}
